<template>
    <el-dialog v-model="dialogVisible" :title="'详情'">
        <xkl-text-form :form="form"></xkl-text-form>
        <template #footer>
            <el-button @click="close()">取消</el-button>
        </template>
    </el-dialog>
</template>
<script setup lang="ts">
export interface DialogDetailInstance {
    init: (id?: number) => void
}
import { ref } from 'vue';
import User from '@/entity/system/user/User';
import UserService from '@/service/module/system/user';
const userService = new UserService()

const form = new User({
    span: 12
}).active

const dialogVisible = ref(false)

const init = (id?: number) => {
    dialogVisible.value = true

    if (id) {
        form.userId = id
    }
    getUserById(form.userId)
}

const getUserById = async (id: number) => {
    const res = await userService.getById(id)
    if (res.SUCCESS) {
        form.setForm(res.data)
        form.postIds = res.postIds
        form.roleIds = res.roleIds
        User.postsResolve(res.posts.map(item => {
            return {
                label: item.postName,
                value: item.postId
            }
        }))

        User.rolesResolve(res.roles.map(item => {
            return {
                label: item.roleName,
                value: item.roleId
            }
        }))
    }
}

const close = () => {
    dialogVisible.value = false
}



defineExpose({ init })
</script>
<style lang="scss" scoped></style>